package com.TripMate.system.service.impl;

import com.TripMate.system.common.ErrorCode;
import com.TripMate.system.exception.BusinessException;
import com.TripMate.system.mapper.FavoritesMapper;
import com.TripMate.system.model.dto.favorites.FavoritesQueryRequest;
import com.TripMate.system.model.entity.Favorites;
import com.TripMate.system.model.vo.FavoritesByPostVO;
import com.TripMate.system.model.vo.FavoritesByTripVO;
import com.TripMate.system.service.FavoritesService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
* @author dongmianyan
* @description 针对表【favorites(收藏表)】的数据库操作Service实现
* @createDate 2024-11-29 18:11:05
*/
@Service
public class FavoritesServiceImpl extends ServiceImpl<FavoritesMapper, Favorites>
    implements FavoritesService {

    @Resource
    private FavoritesMapper favoritesMapper;

    @Override
    public Page<FavoritesByTripVO> getQueryByTrip(Page<FavoritesByTripVO> pageParam, FavoritesQueryRequest favoritesQueryRequest, Long userId) {
        // 自定义分页查询
        List<FavoritesByTripVO> favoritesVOS = favoritesMapper.getQueryByTrip(pageParam, favoritesQueryRequest, userId);
        if (favoritesVOS != null) {
            pageParam.setRecords(favoritesVOS);
            return pageParam;
        } else {
            throw new BusinessException(ErrorCode.OPERATION_ERROR, "查询失败");
        }
    }

    @Override
    public Page<FavoritesByPostVO> getQueryByPost(Page<FavoritesByPostVO> pageParam, FavoritesQueryRequest favoritesQueryRequest, Long userId) {
        // 自定义分页查询
        List<FavoritesByPostVO> favoritesVOS = favoritesMapper.getQueryByPost(pageParam, favoritesQueryRequest, userId);
        if (favoritesVOS != null) {
            pageParam.setRecords(favoritesVOS);
            return pageParam;
        } else {
            throw new BusinessException(ErrorCode.OPERATION_ERROR, "查询失败");
        }
    }

    @Override
    public Page<FavoritesByTripVO> getQueryByTripAll(Page<FavoritesByTripVO> pageParam, FavoritesQueryRequest favoritesQueryRequest) {
        // 自定义分页查询
        List<FavoritesByTripVO> favoritesVOS = favoritesMapper.getQueryByTripAll(pageParam, favoritesQueryRequest);
        if (favoritesVOS != null) {
            pageParam.setRecords(favoritesVOS);
            return pageParam;
        } else {
            throw new BusinessException(ErrorCode.OPERATION_ERROR, "查询失败");
        }
    }

    @Override
    public Page<FavoritesByPostVO> getQueryByPostAll(Page<FavoritesByPostVO> pageParam, FavoritesQueryRequest favoritesQueryRequest) {
        // 自定义分页查询
        List<FavoritesByPostVO> favoritesVOS = favoritesMapper.getQueryByPostAll(pageParam, favoritesQueryRequest);
        if (favoritesVOS != null) {
            pageParam.setRecords(favoritesVOS);
            return pageParam;
        } else {
            throw new BusinessException(ErrorCode.OPERATION_ERROR, "查询失败");
        }
    }
}




